﻿@model IEnumerable<SmallBusinessKit.Models.Entities.Category>

<ul id="tree">
    <li>
        @Ajax.ActionLink("All Items", "GetChildCategories", "Items", new { @id = 0 }, new AjaxOptions { HttpMethod = "post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "TargetDiv", OnFailure = "onFailure" })
        <ul>
            @{
                foreach (var cat in Model)
                {
                    if (cat.ChildCategories.Any())
                    {
                        <li>
                            @Ajax.ActionLink(@cat.Title, "GetChildCategories", "Items", new { @id = cat.Id }, new AjaxOptions { HttpMethod = "post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "TargetDiv", OnFailure = "onFailure" })
                            <ul>
                                @foreach (var subCat in cat.ChildCategories)
                                {
                                    <li>
                                        @Ajax.ActionLink(@subCat.Title, "GetChildItems", "Items", new { @id = subCat.Id }, new AjaxOptions { HttpMethod = "post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "TargetDiv", OnFailure = "onFailure" })
                                    </li>
                                }
                            </ul>
                        </li>
                    }
                    else
                    {
                        <li>@Html.ActionLink(@cat.Title, "Index", new { id = cat.Id })</li>
                    }
                }
            }
        </ul>
    </li>
</ul>